<?php
//App::import('Vendor','tcpdf/tcpdf');
App::import('Vendor','xtcpdf');
$tcpdf = new XTCPDF();
//$tcpdf = new XTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$textfont = 'helvetica';
 
//$tcpdf->SetAuthor("bachpt");
//$tcpdf->SetAutoPageBreak(true);

$tcpdf->setHeaderFont(array($textfont,'',20)); 
$tcpdf->xheadercolor = array(150,0,0); 
$tcpdf->xheadertext = 'Subscribers Report'; 
$tcpdf->xfootertext = 'Beaconschool. All rights reserved.'; 
 
$tcpdf->setPrintHeader(true);
$tcpdf->setPrintFooter(true);

// set default monospaced font
$tcpdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$tcpdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$tcpdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$tcpdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$tcpdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

$tcpdf->SetTextColor(0, 0, 0);
$tcpdf->SetFont($textfont,'',7);
 
$tcpdf->AddPage();
$htmlcontent = "";
foreach ($listSchoolSubscribers as $listSchoolSubscriber) {
	$htmlcontent .= "<h2>{$listSchoolSubscriber['School']['schoolName']} Subscribers Report</h2>";
	// create some HTML content
	$htmlcontent .='<table border="0" cellpadding="1" cellspacing="0" width="100%">
					<tr style="color: #1F4DAF; font-weight: bold;">
					<td width="160px">Username</td>
					<td>Firstname</td>
					<td width="80px">Lastname</td>
					<td width="70px">Mobile</td>
					<td width="160px">Email</td>
					<td width="60px" align="center">User Status</td>
				</tr>';
	$i = 0;
	foreach ($listSchoolSubscriber['Sub'] as $subscriber) {
		$status = $subscriber['User']['active']==1?'Active':'Inactive';
		if ($i%2 != 0) {
			$htmlRow = "<tr style=\"background-color:#EEE;\">";
		} else {
			$htmlRow = "<tr>";
		}
		$htmlRow .= "<td>{$subscriber['User']['userName']}</td>
					<td>{$subscriber['Subscriber']['firstName']}</td>
					<td>{$subscriber['Subscriber']['lastName']}</td>
					<td>{$phone->format_phone($subscriber['Contact']['phone'])}</td>
					<td>{$subscriber['Contact']['email']}</td>
					<td align=\"center\">{$status}</td>
				</tr>";
		// output the HTML content
		$htmlcontent.= $htmlRow;
		$i++;
	}
	$htmlcontent.='</table><p></p>';
}


$image_file = K_PATH_IMAGES.'logoList.jpg';
//$tcpdf->Image($image_file, 100, 100, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);

$tcpdf->writeHTML($htmlcontent, true, 0, true, 0);
$tcpdf->Output('subscribers.pdf', 'D');
?>
